/**
 * Copyright (c) 2019 AsHacker All rights reserved.
 *
 * http://www.ashacker.com
 *
 * 版权所有，侵权必究！
 */

package io.renren.common.utils;

import java.util.*;

/**
 * Map工具类
 *
 * @author Chen chenchen@ashacker.com
 */
public class MapUtils extends HashMap<String, Object> {

    @Override
    public MapUtils put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    /**
     * 求Map<K,V>中Key(键)的最小值
     * @param map
     * @return
     */
    public static Object getMinKey(Map<Integer, Integer> map) {
        if (map == null) return null;
        Set<Integer> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        return obj[0];
    }

    /**
     * 求Map<K,V>中Value(值)的最小值
     * @param map
     * @return
     */
    public static Object getMinValue(Map<Integer, Double> map) {
        if (map == null) return null;
        Collection<Double> c = map.values();
        Object[] obj = c.toArray();
        Arrays.sort(obj);
        return obj[0];
    }

}
